package 深度优先排列_回溯.子集;

import java.util.*;

public class Main {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        if (nums.length == 0) return res;

        Deque<Integer> path = new LinkedList<>();

        dfs(nums, 0, 0, path, res);
        return res;
    }

    private void dfs(int[] nums, int start, int depth, Deque<Integer> path, List<List<Integer>> res) {
        res.add(new ArrayList<>(path));
        if (nums.length == depth) return;

        for (int i = start; i < nums.length; i++) {
            path.add(nums[i]);
            dfs(nums, i + 1, depth + 1, path, res);
            path.removeLast();
        }
    }

    public static void main(String[] args) {
        Main main = new Main();
        int[] nums = {1, 2, 3};
        System.out.println(main.subsets(nums));
    }
}
